import pymongo
from pymongo.results import InsertOneResult,InsertManyResult,DeleteResult
if __name__ == '__main__':
    mongo = pymongo.MongoClient("mongodb://127.0.0.1:27017/")
    # 切换数据库
    my_db = mongo["my_db"]
    # 切换集合
    my_collection = my_db["my_collection"]

    # 删除文档
    # 删除一个文档
    # query = {"name": "xiaoming"}
    # ret = my_collection.delete_one(query)
    # print(ret.raw_result)    # mongo返回的原始操作结果
    # print(ret.deleted_count) # 删除数据量

    # 删除多个文档
    query = {"mobile": {"$regex": "^136"}}
    ret = my_collection.delete_many(query)
    print(ret.raw_result)
    print(f"删除了{ret.deleted_count}个文档")